package com.xt.back.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xt.back.constant.ResultDTO;
import com.xt.back.entity.Course;
import com.xt.back.entity.Relation;
import com.xt.back.service.IRelationService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 关系信息表 前端控制器
 * </p>
 *
 * @author leotong
 * @since 2022-04-03
 */
@CrossOrigin
@RestController
@RequestMapping("/back/relation")
@AllArgsConstructor
public class RelationController {

    private final IRelationService relationService;

    @PostMapping("/add")
    public ResultDTO<Boolean> addCourse(@RequestBody Relation relation){
        return ResultDTO.success(relationService.save(relation));
    }

    @GetMapping("/remove")
    public ResultDTO<Boolean> deleteCourse(int id){
        return ResultDTO.success(relationService.removeById(id));
    }

    @PostMapping("/update")
    public ResultDTO<Boolean> updateCourse(@RequestBody Relation relation){
        return ResultDTO.success(relationService.updateById(relation));
    }

    @PostMapping("/getRelationByPage")
    public ResultDTO<Page<Relation>> getRelationByPage(@RequestBody Relation relation){
        return ResultDTO.success(relationService.getRelationByPage(relation));
    }

    @GetMapping("/getAllRelation")
    public ResultDTO<List<Relation>> getAllRelation(){
        return ResultDTO.success(relationService.list());
    }
}
